# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

set(PATH_TO_MEDIACORE ${CMAKE_SOURCE_DIR}/src/main/cpp/includes)
set(PATH_TO_JNI ${CMAKE_SOURCE_DIR}/src/main/jni)
set(PATH_TO_PRE_BUILT ${CMAKE_SOURCE_DIR}/src/main/cpp/prebuild/${ANDROID_ABI})
set(PATH_TO_SO_LIB ${CMAKE_SOURCE_DIR}/src/main/cpp/prebuild/${ANDROID_ABI})
#set(PATH_TO_SO_LIB ${CMAKE_SOURCE_DIR}/src/main/jniLibs/armeabi-v7a)
#set(PATH_TO_SO_LIB ${CMAKE_SOURCE_DIR}/libs/armeabi-v7a)

add_definitions("
-DGL_GLEXT_PROTOTYPES
-DEGL_EGLEXT_PROTOTYPES
")
#include_directories(
#        "/Users/blensmile/Code/Android/FFmpeg/FFmpeg-n3.2.5/"
#)
include_directories(BEFORE ${PATH_TO_MEDIACORE}/)
#include_directories(/Users/blensmile/Code/Android/FFmpeg/FFmpeg-n3.2.5/)
include_directories(
        ${PATH_TO_JNI}/
#        /Users/blensmile/Code/Android/FFmpeg/FFmpeg-n3.2.5/
)



# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
#add_library(avutil
#        STATIC
#        IMPORTED)
#set_target_properties(avutil
#        PROPERTIES IMPORTED_LOCATION
#        ${PATH_TO_SO_LIB}/libavutil.a)
#
#add_library(avcodec
#        STATIC
#        IMPORTED)
#set_target_properties(avcodec
#        PROPERTIES IMPORTED_LOCATION
#        ${PATH_TO_SO_LIB}/libavcodec.a)
#
#add_library(avfilter
#        STATIC
#        IMPORTED)
#set_target_properties(avfilter
#        PROPERTIES IMPORTED_LOCATION
#        ${PATH_TO_SO_LIB}/libavfilter.a)
#
#add_library(avformat
#        STATIC
#        IMPORTED)
#set_target_properties(avformat
#        PROPERTIES IMPORTED_LOCATION
#        ${PATH_TO_SO_LIB}/libavformat.a)
#
#add_library(swresample
#        STATIC
#        IMPORTED)
#set_target_properties(swresample
#        PROPERTIES IMPORTED_LOCATION
#        ${PATH_TO_SO_LIB}/libswresample.a)
#
#add_library(swscale
#        STATIC
#        IMPORTED)
#set_target_properties(swscale
#        PROPERTIES IMPORTED_LOCATION
#        ${PATH_TO_SO_LIB}/libswscale.a)

#add_library(fdk-aac
#        SHARED
#        IMPORTED)
#set_target_properties(fdk-aac
#        PROPERTIES IMPORTED_LOCATION
#        ${PATH_TO_SO_LIB}/libfdk-aac.so)

#add_library(x264
#        SHARED
#        IMPORTED)
#set_target_properties(x264
#        PROPERTIES IMPORTED_LOCATION
#        ${PATH_TO_SO_LIB}/libx264.so)

file(GLOB FILES_CPP "${PATH_TO_JNI}/*.cpp")
file(GLOB FILES_C "${PATH_TO_JNI}/*.c")
add_library( # Sets the name of the library.
        native-li
        # Sets the library as a shared library.
        SHARED
        # Provides a relative path to your source file(s).
#        ${PATH_TO_JNI}/native-lib.cpp
        ${FILES_CPP}
        ${FILES_C}
#        ${PATH_TO_JNI}/cmd.c
#        ${PATH_TO_JNI}/cmdutils.c
#        ${PATH_TO_JNI}/ffmpeg.c
#        ${PATH_TO_JNI}/ffmpeg_filter.c
#        ${PATH_TO_JNI}/ffmpeg_opt.c

        )

#include_directories(${PATH_TO_MEDIACORE})
# before很关键啊, 没有, 爆了很多莫名其妙的错
#include_directories(AFTER ${PATH_TO_MEDIACORE})
#include_directories(AFTER ${PATH_TO_MEDIACORE}/compat)
#include_directories(AFTER ${PATH_TO_MEDIACORE}/libavcodec)
#include_directories(AFTER ${PATH_TO_MEDIACORE}/libavdevice)
#include_directories(AFTER ${PATH_TO_MEDIACORE}/libavfilter)
#include_directories(AFTER ${PATH_TO_MEDIACORE}/libavformat)
#include_directories(AFTER ${PATH_TO_MEDIACORE}/libavresample)
#include_directories(AFTER ${PATH_TO_MEDIACORE}/libavutil)
#include_directories(AFTER ${PATH_TO_MEDIACORE}/libpostproc)
#include_directories(AFTER ${PATH_TO_MEDIACORE}/libswresample)
#include_directories(AFTER ${PATH_TO_MEDIACORE}/libswscale)


#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
        native-li
#        avcodec avfilter avformat avutil swresample swscale
#        x264
#        fdk-aac
        # Links the target library to the log library
        # included in the NDK.
        log
        ${log-lib}
        android
        GLESv2
        EGL
        z
        OpenSLES
        # 引入ffmpeg相关静态库
        ${PATH_TO_PRE_BUILT}/libavfilter.a
        ${PATH_TO_PRE_BUILT}/libavformat.a
        ${PATH_TO_PRE_BUILT}/libavcodec.a
        ${PATH_TO_PRE_BUILT}/libpostproc.a
        ${PATH_TO_PRE_BUILT}/libswresample.a
        ${PATH_TO_PRE_BUILT}/libswscale.a
        ${PATH_TO_PRE_BUILT}/libavutil.a
        ${PATH_TO_PRE_BUILT}/libfdk-aac.a
        ${PATH_TO_PRE_BUILT}/libvo-aacenc.a
        ${PATH_TO_PRE_BUILT}/libx264.a
#        ${PATH_TO_PRE_BUILT}/libsox.a
        ${PATH_TO_PRE_BUILT}/libmp3lame.a
        )